%%%-----------------------------------
%%% @Module  : pt_27
%%% @Author  : xws
%%% @Created : 2017.1.2
%%% @Description: pt_27
%%%-----------------------------------
-module(pt_27).
-export([read/2, write/2]).
-include("common.hrl").
-include("proto_27_share_shop.hrl").

%%
%%客户端 -> 服务端 ----------------------------
%%

%% c2s获取商城物品
read(27000, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_get_share_shop_goods, Bin),	
	{c2s_get_share_shop_goods, GoodsType} = ClientData,
    {ok, [GoodsType]};

%% 27001 c2s购买物品
read(27001, Bin) ->
	{ClientData, _} = proto_read:unpack(c2s_buy_share_shop_goods, Bin),	
	{c2s_buy_share_shop_goods, GoodsId, Num} = ClientData,
    {ok, [GoodsId, Num]};

read(_Cmd, _R) ->
    ?ERROR_MSG("~s pt_14 reading cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), _Cmd, _R]),
    {error, no_match}.

%%
%%服务端 -> 客户端 ------------------------------------
%%
%% s2c获取商城物品
write(27000, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_get_share_shop_goods, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(27000, ServerData)};

%% s2c 购买物品
write(27001, [Seq, RecordData]) ->
    MsgPack = proto_write:pack(s2c_buy_share_shop_goods, RecordData),
    ServerData = <<Seq:32, MsgPack/binary>>,
    {ok, pt:pack(27001, ServerData)};

write(Cmd, _R) ->
    ?ERROR_MSG("~s pt_14 writting cmd_[~p], Data:~p~n",[misc:time_format(game_timer:now()), Cmd, _R]),
    {ok, pt:pack(0, <<>>)}.
